<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<script type="text/javascript" >
function saveChangePwd() {
	var oldPassword = $("#oldPassword").val();
	var newPassword = $("#newPassword").val();
	var confirmPassword = $("#confirmPassword").val();
	
	if (oldPassword == "") {
		alert("请输入旧密码!");
		$("#oldPassword").focus();
	}
	
	if (newPassword == "") {
		alert("请输入新密码!");
		$("#newPassword").focus();
	}
	
	if (confirmPassword == "") {
		alert("请再次输入密码!");
		$("#confirmPassword").focus();
	}
	
	if (newPassword != confirmPassword) {
		alert("两次密码输入不一致!");
		$("#confirmPassword").focus();
	}
	
	ajaxPost('<s:url action="change-password" namespace="/admin/user" />', {"oldPassword": oldPassword, "newPassword": newPassword},
		function(response){
			var status = response.status;
			if(status == 200) {
				alert("密码修改成功，下次登录请用新密码！");
				closeChangeModal();
			} else {
				alert("密码修改失败!");
			}
		}
	);
	
}
</script>
<script src="<s:url value='/admin/js/change-pwd.js' />" type="text/javascript"></script>

<div id="changePwdModal" class="modal fade" tabindex="-1" >
	<div class="modal-dialog" style="width: 400px; margin-top: 100px">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true"></button>
				<h4 class="modal-title">修改密码</h4>
			</div>
			<div class="modal-body">
				<div data-always-visible="1" data-rail-visible1="1" style="min-height: 90px; height:auto;">
	                    <form id="changePwdFrm" >
	                    	<div class="input-group" >
		                    	<label class="col-md-3 control-label" style="width: 100px;" >&nbsp;&nbsp; 旧密码：</label>
		                    	<s:password id="oldPassword" name="oldPassword" cssClass="form-control" cssStyle="width: 200px" maxlength="20" />
		                    </div>
	                    	<div class="input-group" >
		                    	<label class="col-md-3 control-label" style="width: 100px;" >&nbsp;&nbsp; 新密码：</label>
		                    	<s:password id="newPassword" name="newPassword" cssClass="form-control" cssStyle="width: 200px" maxlength="20" />
		                    </div>
	                    	<div class="input-group" >
		                    	<label class="col-md-3 control-label" style="width: 100px" >确认密码：</label>
		                    	<s:password  name="confirmPassword" cssClass="form-control" cssStyle="width: 200px" maxlength="20" />
		                    </div>
	                    </form>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" onclick="closeChangeModal()" class="btn btn-default">关闭</button>
				<button type="button" onclick="saveChangePwd()" class="btn btn-success">保存</button>
			</div>
		</div>
	</div>
</div>